package net.chathu.airgw.model 
{
	import flash.utils.Dictionary;
	/**
	 * ...
	 * @author ze
	 */
	public class ChannelList 
	{
		
		private var channeldict:Dictionary;
		public function ChannelList() 
		{
			channeldict = new Dictionary();
		}
		
		public function add(roo,:Room):Boolean
		{
			if (!contains(user))
			{
				channeldict[user.id] = user;
				return true;
			} else {
				return false;
			}
		}
		
		public function remove(user:User):Boolean
		{
			if (contains(user))
			{
				delete channeldict[user.id];
				return true;
			} else {
				return false;
			}
		}
		
		public function contains(user:User):Boolean
		{
			return !!(channeldict[user.id]);
		}
		
		public function clear():void
		{
			channeldict = new Dictionary();	
		}
		
		public function getUser(id:int):User
		{
			return channeldict[id];		
		}
		
		public function getUserByRegID(regid:int):User
		{
			for (var key:* in channeldict)
			{
				var user:User = channeldict[key];
				if (user.regId == regid)
				{
					return user;
				}
			}	
			return null;
		}
				
		public function getChannelNum():int
		{
			var n:int = 0;
			for (var key:* in channeldict)
			{
				n++;
			}	
			return n;
		}
		
		public function getUserByName(name:String):User
		{
			
			for (var key:* in channeldict)
			{
				var user:User = channeldict[key];
				if (user.name == name)
				{
					return user;
				}
			}	
			return null;
		}
		
		
	}

}